package part17;

import java.util.ArrayList;
import java.util.Collections;

/**
 * @author wcj
 * @Date 2021/6/1 15:48
 * @Version 1.0
 */
public class Part171 {

    /**
     * 两种填充容器的方法：
     * Collections.nCopies()
     * Collections.fill()
     * 第二个方法更加受限，因为其只能替换元素
     *
     * @param args
     */
    public static void main(String[] args) {
        ArrayList<StringAddress> list = new ArrayList<>(Collections.nCopies(4, new StringAddress("hello")));
        System.out.println(list);
        Collections.fill(list, new StringAddress("world"));
        System.out.println(list);
    }

}

class StringAddress {
    private String s;

    public StringAddress(String s) {
        this.s = s;
    }

    @Override
    public String toString() {
        return super.toString() + " " + s;
    }
}
